package midianet.digital.persistencia;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import midianet.digital.modelo.Municipio;

import org.springframework.stereotype.Repository;

@Repository
public class MunicipioDAO {
	
	@PersistenceContext
	protected EntityManager persistencia;
	
	@SuppressWarnings("unchecked")
	public String pegaNome(){
		
	    try{
	        final Query consulta =  persistencia.createNamedQuery("Municipio.listarTodos");

		List<Municipio> cidades  = consulta.getResultList();
	       
	       return cidades.get(0).getNome();
	    }catch(final Exception e){
	    	System.out.println(e.getMessage());
	    }
	    
	    return null;
	}
	
}
